import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'
import Home from '../views/Home.vue'

const routes: Array<RouteRecordRaw> = [
  {
    path: '/',
    component: () => import('../views/beforeHome.vue'),
    redirect: '/home',
    children: [
      {
        path: '/home',
        name: 'Home',
        meta: { title: '首页' },
        component: Home,
      },
      {
        path: '/achievement',
        name: 'achievement',
        meta: { title: '成果分享' },
        component: () => import('../views/achievement.vue'),
      },
      {
        path: '/article',
        name: 'article',
        meta: { title: '团队动态' },
        component: () => import('../views/article.vue'),
      },
      {
        path: '/show',
        name: 'show',
        meta: { title: '成员展示' },
        component: () => import('../views/membershow.vue'),
        // children: [
        //   {
        //     path: 'all',
        //     name: 'all',
        //   }
        // ]
      },
      {
        path: '/resourceshare',
        name: 'resourceshare',
        meta: { title: '资源分享' },
        component: () => import('../views/resourceshare.vue'),
      },
      {
        path: '/album',
        name: 'album',
        meta: { title: '团队风采' },
        component: () => import('@/views/album.vue'),
      },
      {
        path: '/login',
        name: 'Login',
        meta: { title: '登录' },
        component: () => import('@/views/login/loginMy.vue'),
      },
      {
        path: '/register',
        name: 'Register',
        meta: { title: '注册' },
        component: () => import('@/views/login/registerMy.vue'),
      },
      {
        path: '/userHome',
        name: 'userHome',
        meta: { title: '个人主页' },
        component: () => import('../components/other/userHome.vue'),
      },
      {
        path: '/articleDetails',
        name: 'ArticleDetails',
        meta: { title: '文章详情' },
        component: () => import('../components/other/articleDetails.vue'),
      },
      {
        path: '/changInfo',
        name: 'ChangInfo',
        meta: { title: '编辑个人资料' },
        component: () =>
          import('../components/userToolPage/changeUserInfo.vue'),
      },
      {
        path: '/resourceIssue',
        name: 'AddResource',
        meta: { title: '资源分享' },
        component: () => import('../components/userToolPage/addResource.vue'),
      },
      {
        path: '/editResource',
        name: 'editResource',
        meta: { title: '资源分享' },
        component: () => import('../components/userToolPage/editResource.vue'),
      },
      {
        path: '/addAchivement',
        name: 'addAchivement',
        meta: { title: '成果发布' },
        component: () =>
          import('../components/userToolPage/addAchievement.vue'),
      },
      {
        path: '/editAchivement',
        name: 'editAchivement',
        meta: { title: '成果编辑' },
        component: () =>
          import('../components/userToolPage/EditAchievement.vue'),
      },
      {
        path: '/articleEdit',
        name: 'AtcEdit',
        component: () => import('../components/userToolPage/Editarticle.vue'),
      },
      {
        path: '/addArticle',
        name: 'addArticle',
        component: () => import('../components/userToolPage/addArticle.vue'),
      },
    ],
  },
  {
    path: '/:pathMatch(.*)*', // 页面不存在的情况下会跳到404页面
    meta: { title: '页面不存在' },
    component: () => import('@/views/errorPage.vue'),
  },
]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  },
})

export default router
